package com.jinmdz.fmis.dao.dao;

import com.jinmdz.fmis.dao.dao.provider.ChargeSettlePayProvider;
import com.jinmdz.fmis.dao.model.settlement.ChargeSettlePayItem;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;

import java.util.ArrayList;

/**
 * 费用结算付款Dao
 *
 * @author LiCongLu
 * @date 2020-02-19 11:45
 */
public interface ChargeSettlePayDao {

    /**
     * 按照主键获取费用结算付款信息
     *
     * @param id 主键
     * @return
     * @author LiCongLu
     * @date 2020-02-19 11:49
     */
    @Select(" select id,business_code,charge_settle_id,pay_type_code,pay_charge,pay_time,random_code,version " +
            " from charge_settle_pay where id = #{id} and deleted=0 ")
    ChargeSettlePayItem getChargeSettlePayById(@Param("id") Integer id);

    /**
     * 撤销结算时，删除付款信息
     *
     * @param businessCode   业务编码
     * @param chargeSettleId 主键
     * @param modifiedUserId 修改用户外键
     * @return
     * @author LiCongLu
     * @date 2020-02-20 13:33
     */
    @Update(" update charge_settle_pay set deleted = 1,modified_user_id = #{modifiedUserId},version = unix_timestamp(now()) where business_code = #{businessCode} and charge_settle_id = #{chargeSettleId} and unmodified = 0 and deleted = 0 ")
    void deletedForCancellationSettlement(@Param("businessCode") String businessCode, @Param("chargeSettleId") Integer chargeSettleId, @Param("modifiedUserId") Integer modifiedUserId);

    /**
     * 按照业务编码获取付款信息
     *
     * @param businessCode 业务编码
     * @return
     * @author LiCongLu
     * @date 2020-02-20 14:39
     */
    @Select(" select id,business_code,charge_settle_id,pay_type_code,pay_charge,pay_time,random_code,version " +
            " from charge_settle_pay where business_code = #{businessCode} and deleted = 0 ")
    ArrayList<ChargeSettlePayItem> listChargeSettlePayByBusinessCode(@Param("businessCode") String businessCode);

    /**
     * 按照结算主键获取付款信息
     *
     * @param businessCode 业务编码
     * @param settleIds    结算主键集合
     * @return
     * @author LiCongLu
     * @date 2020-05-13 15:10
     */
    @SelectProvider(type = ChargeSettlePayProvider.class, method = "listChargeSettlePayBySettleIds")
    ArrayList<ChargeSettlePayItem> listChargeSettlePayBySettleIds(@Param("businessCode") String businessCode, @Param("settleIds") ArrayList<Integer> settleIds);

}
